script_enemy_main{

let shot1=0;
let bullet1=[];
let timer1=[];

let phase=0;
let bombangle=0;
let shots=0;

let angle1=0;

let character="Ryo";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=19;
let damagerate=10;
let outfit=4;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEthrow1=("\script\SoundEffects\throw1.wav");
let SEexplodes2=("script\SoundEffects\explodes2.wav");
let SEshots5=("script\SoundEffects\shots5.wav");

let BG1=("\script\Images\BackgroundLayers\Ryo2.png");
let GRboss=("\script\Images\CharacterSprites\Ryo.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsRyo1.txt");

	LoadSE("\script\SoundEffects\throw1.wav");
	LoadSE("script\SoundEffects\explodes2.wav");
	LoadSE("script\SoundEffects\shots5.wav");

	LoadGraphic("\script\Images\BackgroundLayers\Ryo2.png");
	LoadGraphic("\script\Images\CharacterSprites\Ryo.png");

	SetScore(200000);
	SetLife(400);
	SetTimer(45);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+100,50);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(32,32,32,32);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=8; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("Metsubushi [Concealing Wall Of Smoke] ("~difficulty~")",spellcardnumber); 
HealthBar();
Portrait(cutin,1);


if(time%90==0 && time>=60){
let angle=0;
SetShotDirectionType(PLAYER);
	loop(60){
	CreateShot02(GetX-10,GetY-25,6,angle,-0.07,2,73,0);
	angle+=360/60;
	}
SetShotDirectionType(ABSOLUTE);
if(usespell>=0){ usespell=20; }
PlaySE(SEthrow1);
}


//============================================================================================

//PHASE 0

if(time%200==0 && time>=60 && ((phase+0)%3==0 || (phase+2)%3==0)){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+90,miny+120),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+90,miny+120),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+90,miny+120),1.5);
	}
}

if((phase+0)%3==0 && frame==0){
	bombangle=GetAngleToPlayer+70;
	shots=0;
}

if(frame>=80 && time%5==0 && shots<45 && (phase+0)%3==0){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY-15);
	Obj_SetAngle(shot1,90+90*cos(time*2));
	Obj_SetSpeed(shot1,rand(3.5,5));
	ObjShot_SetGraphic(shot1,12);
	Obj_SetCollisionToPlayer(shot1,false);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
bombangle-=140/15;
shots++;
usespell=-20;
}

if(shots>=5 && shots<40 && time%7==0 && (phase+0)%3==0){
let angle=0;
	loop(34){
	CreateShot01(GetX,GetY-15,2.4+0.7*cos(angle*3)+rand(0,0.3),angle+angle1+rand(-2,2),15,0);
	angle+=360/34;
	}
angle1-=4;
usespell=-10;
PlaySE(SEshots5);
}

if(shots>=45 && (phase+0)%3==0){ phase++; shots=0; frame=0; }

//============================================================================================

//PHASE 1

if((phase+2)%3==0 && frame==0){ bombangle=rand(0,360); }

if(frame>=80 && time%5==0 && shots<60 && (phase+2)%3==0){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY-15);
	Obj_SetAngle(shot1,bombangle+rand(-10,10));
	Obj_SetSpeed(shot1,rand(2.5,3.5)+shots/20);
	ObjShot_SetGraphic(shot1,12);
	Obj_SetCollisionToPlayer(shot1,false);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
bombangle+=83;
shots++;
usespell=-20;
}

if(shots>=10 && shots<50 && time%20==0 && (phase+2)%3==0){
let angle=90;
if(time%40==0){ angle+=360/160; }
	loop(80){
	CreateShot01(GetX,GetY-15,4,angle,15,0);
	angle+=360/80;
	}
usespell=-10;
PlaySE(SEshots5);
}

if(shots>=60 && (phase+2)%3==0){ phase++; shots=0; frame=0; }

//============================================================================================

//PHASE 2

if((phase+1)%3==0 && frame==0){ bombangle=rand(0,360); }

if((phase+1)%3==0 && (time-30)%180==0){ SetMovePosition03(cx+150,miny+120,8,5); }
if((phase+1)%3==0 && (time-120)%180==0){ SetMovePosition03(cx-150,miny+120,8,5); }

if((time+45)%180==0 || (time+135)%180==0 && time>=60){
let angle=0;
SetShotDirectionType(PLAYER);
	loop(60){
	CreateShot02(GetX-10,GetY-25,6,angle,-0.07,2,73,0);
	angle+=360/60;
	}
SetShotDirectionType(ABSOLUTE);
if(usespell>=0){ usespell=20; }
PlaySE(SEthrow1);
}

if(frame>=80 && time%8==0 && shots<30 && (phase+1)%3==0){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY-15);
	Obj_SetAngle(shot1,GetAngleToPlayer+rand(-15,15));
	Obj_SetSpeed(shot1,rand(3.5,5));
	ObjShot_SetGraphic(shot1,12);
	Obj_SetCollisionToPlayer(shot1,false);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
shots++;
usespell=-20;
bombangle+=20;
}

if(time%7==0 && shots>=5 && shots<25 && (phase+1)%3==0){
	SetShotDirectionType(PLAYER);
	let anglex=-7;
	loop(5){
	CreateShot01(GetX,GetY-15,5,anglex,15,0);
	CreateShot01(GetX,GetY-15,5,anglex,27,0);
	CreateShot01(GetX,GetY-15,5,anglex,15,0);
	anglex+=3.5;
	}
	SetShotDirectionType(ABSOLUTE);
usespell=-10;
PlaySE(SEshots5);
}



if(shots>=30 && (phase+1)%3==0){ phase++; shots=0; frame=0; }




let i=0;
while (i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){ bullet1=erase(bullet1,i); timer1=erase(timer1,i); i--; }
	else{
		if(Obj_GetSpeed(bullet1[i])>0){ Obj_SetSpeed(bullet1[i],Obj_GetSpeed(bullet1[i])-0.05); }
		if(Obj_GetSpeed(bullet1[i])<0){ Obj_SetSpeed(bullet1[i],0); }
		if(timer1[i]>=60){
if((phase+0)%3){ CreateEnemyFromFile(GetCurrentScriptDirectory~"Ryo - Concealing Wall Of Smoke - Familiar.txt",Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,0,60); }
if((phase+2)%3){ CreateEnemyFromFile(GetCurrentScriptDirectory~"Ryo - Concealing Wall Of Smoke - Familiar.txt",Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,0,20); }
if((phase+1)%3){ CreateEnemyFromFile(GetCurrentScriptDirectory~"Ryo - Concealing Wall Of Smoke - Familiar.txt",Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,0,40); }
		Obj_Delete(bullet1[i]);
		PlaySE(SEexplodes2);
		}
	timer1[i]=timer1[i]+1;
	}
i++;
}


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
	if(bgfade<255){ bgfade+=5; }

	SetGraphicRect(0,0,300,300);
	SetTexture(BG1);
	SetGraphicScale(4,4);
	SetAlpha(bgfade*0.75);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,time/2);
	DrawGraphic(cx,maxy+40);
	
	SetAlpha(bgfade*0.75);
	SetGraphicAngle(0,0,-time/1.9);
	DrawGraphic(cx,maxy+40);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
	SetShotAutoDeleteClip(150,150,150,150);
	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,GetCommonData("Difficulty"));
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}